package com.ruoyi.chat.service.impl;

import com.ruoyi.chat.domain.ChatContent;
import com.ruoyi.chat.mapper.ChatContentMapper;
import com.ruoyi.chat.service.ChatContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * @Classname ContentServiceImpl
 * @Description
 * @Date 2025/5/21 18:23
 * @Created by 高合吴彦祖鹏哥
 */
@Component
public class ContentServiceImpl implements ChatContentService {

    @Autowired
    private ChatContentMapper contentMapper;

    @Override
    public void insert(ChatContent content) {
        contentMapper.insert(content);
    }

    @Override
    public void delete(Long id) {
        contentMapper.deleteById(id);
    }

    @Override
    public void update(ChatContent content) {
        delete(content.getId());
        insert(content);
    }

    @Override
    public ChatContent select(Long id) {
        Optional<ChatContent> content = contentMapper.findById(id);
        return content.orElse(new ChatContent());
    }

    @Override
    public List<ChatContent> selectAll() {
        return contentMapper.findAll();
    }
}